package com.tingyuge.base.jdk.io.nio.files;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * @author xiaodao
 * @version 1.0
 * @description
 */
public class FilesDemo {

    public static void main(String[] args) throws IOException {
        Path rootPath = Paths.get("d:\\nio");

        String fileToFind = File.separator + "002.txt";
        try {

            Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws   IOException {
                    String fileString = file.toAbsolutePath().toString();
                        //System.out.println("pathString = " + fileString);

                    if (fileString.endsWith(fileToFind)) {

                        System.out.println("file found at path: " + file.toAbsolutePath());

                      //  return FileVisitResult.SKIP_SIBLINGS;

                    }

                    return FileVisitResult.CONTINUE;

                }

            });

        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
